<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %><%--
  Created by IntelliJ IDEA.
  User: DE
  Date: 2019/4/9
  Time: 17:47
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
%>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>工单信息</title>
    <link href="<%=basePath%>resources/layui/css/layui.css" rel="stylesheet"></link>
    <link href="<%=basePath%>resources/css/style.css" rel="stylesheet"></link>

    <style>
        .layui-fixbar{
            width: 40px;
        }

    </style>
</head>
<body>
<!-- layout admin -->
<div class="layui-layout layui-layout-admin"> <!-- 添加skin-1类可手动修改主题为纯白，添加skin-2类可手动修改主题为蓝白 -->
    <!-- header -->
    <div class="layui-header my-header">
        <a href="<c:if test="${user.usertype==1}"><%=basePath%>order/orderlist</c:if><c:if test="${user.usertype==0}"><%=basePath%>page/manager/orderManager</c:if>">
            <!--<img class="my-header-logo" src="" alt="logo">-->
            <div class="my-header-logo">校园便捷服务平台</div>
        </a>


        <!-- 顶部右侧添加选项卡监听 -->
        <ul class="layui-nav my-header-user-nav" lay-filter="side-top-right">
            <li class="layui-nav-item"><span id="datetime"></span>&nbsp;</li>
            <li class="layui-nav-item">
                <a href="<c:if test="${user.usertype==1}"><%=basePath%>order/orderlist</c:if><c:if test="${user.usertype==0}"><%=basePath%><%=basePath%>page/manager/orderManager</c:if>">主页</a>
            </li>
            <li class="layui-nav-item">
                <a href="<%=basePath%>order/acceptOrderlist">我的订单<!--<span class="layui-badge">9</span>--></a>
            </li>
            <li class="layui-nav-item">
                <a href="<%=basePath%>page/user/personalCenter">个人中心<!--<span class="layui-badge-dot"></span>--></a>
            </li>
            <li class="layui-nav-item">
                <a href="<%=basePath%>page/user/personalCenter"><c:if test="${user.userimg!=null}"><img
                        src="<%=basePath%>${user.userimg}" class="layui-nav-img"></c:if>${user.username}</a>
                <dl class="layui-nav-child">
                    <dd><a href="javascript:;" onclick="logout()">退出系统</a></dd>
                </dl>
            </li>
        </ul>

    </div>
    <!-- body -->
    <div class="layui-body my-body" style="background-color: #F6F6F6">

        <div class="layui-tab-content">
            <div class=" layui-fluid">
                <div class="layui-row">
                    <form class="layui-form layui-col12" lay-filter="orderForm" action="" method="post">
                        <div class="layui-form-item layui-col-xs12 layui-col-md12">
                            <label class="layui-form-label">标题</label>
                            <div class="layui-input-inline">
                                <input type="text" name="ordertitle" autocomplete="off" placeholder="请输入标题"
                                       class="layui-input" value="${order.ordertitle}">
                            </div>
                            <label class="layui-form-label">订单号</label>
                            <div class="layui-input-inline">
                                <input type="text" lay-verify="number" name="ordernum" autocomplete="off"
                                       placeholder="请输入订单号" readonly="readonly" class="layui-input"
                                       value="${order.ordernum}">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-xs12 layui-col-md12">
                            <label class="layui-form-label">发布人</label>
                            <div class="layui-input-inline">
                                <input type="text" id="userID" name="releaseusername" autocomplete="off"
                                       placeholder="发布人" class="layui-input" readonly="readonly"
                                       value="${order.releaseusername}">
                            </div>
                            <label class="layui-form-label">发布人电话</label>
                            <div class="layui-input-inline">
                                <input type="text" lay-verify="number" autocomplete="off" placeholder="发布人电话"
                                       name="releaseuserphone" readonly="readonly" class="layui-input"
                                       value="${order.releaseuserphone}">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-xs12 layui-col-md5 ">
                            <div class="layui-inline">
                                <label class="layui-form-label">发布时间</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="createTime" name="createTime" autocomplete="off"
                                           placeholder="yyyy-MM-dd HH:mm:ss" class="layui-input" readonly="readonly"
                                           value="<fmt:formatDate value="${order.createtime}" pattern="yyyy-MM-dd HH:mm:ss"/>">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-xs12 layui-col-md12">
                            <label class="layui-form-label">接受人</label>
                            <div class="layui-input-inline">
                                <input type="text" id="acceptusername" readonly="readonly" name="acceptuserid"
                                       autocomplete="off" placeholder="请输入接受人" class="layui-input"
                                       value="${order.acceptusername}">
                            </div>
                            <label class="layui-form-label">接受人电话</label>
                            <div class="layui-input-inline">
                                <input type="text"  autocomplete="off" placeholder="接受人电话"
                                       name="acceptuserphone" readonly="readonly" class="layui-input"
                                       value="${order.acceptuserphone}">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-xs12 layui-col-md5">
                            <label class="layui-form-label">完成时间</label>
                            <div class="layui-input-inline">
                                <input type="text" id="finishTime" name="finishtime" placeholder="yyyy-MM-dd HH:mm:ss"
                                       autocomplete="off" class="layui-input" readonly="readonly"
                                       value="<fmt:formatDate value="${order.finishtime}" pattern="yyyy-MM-dd HH:mm:ss"/>">

                            </div>
                        </div>
                        <div class="layui-form-item layui-col-xs12 layui-col-md12">
                            <label class="layui-form-label">内容</label>
                            <div class="layui-input-block">
                                <input placeholder="请输入内容" class="layui-textarea" id="deduction" name="deduction"
                                       value="${order.orderbody}">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-xs12 layui-col-md12">
                            <label class="layui-form-label">订单状态</label>
                            <div class="layui-input-block">
                                <input type="checkbox" name="acceptStatus" readonly="readonly" id="acceptStatus"
                                       title="接受"
                                       <c:if test="${order.accpetstatus==1}">checked</c:if> >
                                <input type="checkbox" name="finishStatus" readonly="readonly" id="finishStatus"
                                       title="完成"
                                       <c:if test="${order.finishstatus==1}">checked</c:if> >
                                <input type="checkbox" name="commentStatus" readonly="readonly" id="commentStatus"
                                       title="评论"
                                       <c:if test="${order.commentstatus==1}">checked</c:if> >
                                <%--<input type="checkbox" name="payStatus" id="payStatus" title="支付" >--%>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-xs12 layui-col-md12">
                            <label class="layui-form-label">订单标签</label>
                            <div class="layui-input-inline"  id="ordertag">

                            </div>
                        </div>

                        <c:if test="${order.accpetstatus==0&&order.userid==user.userid||user.usertype==0}">
                        <div class="layui-form-item layui-col-xs12 layui-col-md12">
                            <label class="layui-form-label">添加标签</label>
                            <div class="layui-input-block">
                                <select name="addordertag" id="addordertag" class="layui-select layui-inline"  lay-filter="xmFilter">
                                    <option value=""></option>
                                </select>
                                <input value="添加" class="layui-btn layui-btn-danger layui-inline" onclick="addTag()">
                            </div>
                        </div>
                        </c:if>
                        <div class="layui-form-item layui-col-xs12 layui-col-md12">
                            <label class="layui-form-label">评论星级</label>
                            <div class="layui-input-inline" id="commentStart">
                            </div>
                            <input style="display: none" name="commentstart" value="${order.commentstart}">
                            <input style="display: none" name="userid" value="${order.userid}">
                            <input style="display: none" name="id" value="${order.id}">
                        </div>
                        <c:set var="releaseUserId" value="${sessionScope.user.userid}"/>
                        <c:if test="${order.userid==releaseUserId||user.usertype==0}">
                            <div class="layui-form-item layui-col-xs12 layui-col-md12">

                                <div class="layui-col-md2 layui-col-sm2  layui-col-sm-offset1 layui-col-md-offset1">
                                    <button type="button" class="layui-btn layui-inline" lay-submit=""
                                            lay-filter="userSave">保存
                                    </button>
                                </div>

                                <div class="layui-col-md2 layui-col-sm2  layui-col-sm-offset1 layui-col-md-offset3">
                                    <button type="button" class="layui-btn layui-inline" lay-submit=""
                                            lay-filter="userComplain">投诉
                                    </button>
                                </div>
                                <c:if test="${order.accpetstatus==0}">
                                    <div class="layui-col-md2 layui-col-sm2  layui-col-sm-offset1 layui-col-md-offset1">
                                        <button type="button" class="layui-btn layui-block" lay-submit=""
                                                lay-filter="cancelOrder">取消订单
                                        </button>
                                    </div>

                                </c:if>

                            </div>
                        </c:if>

                    </form>
                </div>


            </div>

        </div>


    </div>

</div>
<script type="text/javascript" src="<%=basePath%>resources/jquery-3.2.1/jquery-3.2.1.js"></script>
<script src="<%=basePath%>resources/layui/layui.js"></script>
<script src="<%=basePath%>resources/js/vip_comm.js"></script>
<script src="<%=basePath%>resources/js/functionList.js"></script>
<script type="text/javascript">
    layui.use(['form', 'layer', 'rate', 'laydate'], function () {        // 操作对象
        var layer = layui.layer;
        var element = layui.element;
        var laydate = layui.laydate;
        var form = layui.form;
        var rate = layui.rate;
        var $ = layui.jquery;


        var commentStart = rate.render({
            elem: '#commentStart'
            , value: '${order.commentstart}' //初始值
            , choose: function (value) {
                $.ajax({
                    type: "POST",
                    url: "<%=basePath%>order/commentOrder",
                    data: {'id':${order.id}, 'commentstart': value},
                    success: function (data) {
                        console.log(JSON.stringify(data.data));
                        layer.msg(data.msg);
                    }
                });


            }
            /*  , text: true*/
        });

        $.ajax({
            type: "POST",
            url: "<%=basePath%>tag/alltagbyorder",
            data: {'id':${order.id}},
            success: function (data) {
                $.each(data.data, function (index, item) {
                   /* console.log(JSON.stringify(item));*/
                    $('#ordertag').append(
                        "<input type='checkbox' readonly='readonly' title='"+item.tagname.toString()+"' checked >"
                    );

                });
                form.render();
            }
        });


        $.ajax({
            url: '<%=basePath%>tag/alltag',
            dataType: 'json',
            type: 'get',
            success: function (data) {
                console.log(JSON.stringify(data.data));
                $.each(data.data, function (index, item) {
                    /*console.log(JSON.stringify(item));*/
                    $('#addordertag').append(
                        "<option value='"+JSON.stringify(item.id)+"'>"+item.tagname.toString()+"</option>");
                    /* new Option(item.username, item.userid));// 下拉菜单里添加元素*/
                });
                layui.form.render("select");


            }
        });

        addTag = function () {

            $.ajax({
                type: "post",
                url: "<%=basePath%>tag/addOrderTag",
                data:{'orderid':${order.id},
                    'tagid':$("#addordertag option:selected").val(),
                    'userid':${order.userid}
                },
                success: function(datas){
                layer.msg(datas.msg);

                    if (datas.code==0){
                        $('#ordertag').append(
                            "<input type='checkbox' readonly='readonly' title='"+$("#addordertag option:selected").text()+"' checked >"
                        );
                        layui.form.render("checkbox");
                    }


                }});





        }



        /**
         * 保存工单
         * */

        form.on('submit(userSave)', function (data) {
            /*layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            });*/

            $.ajax({
                type: "POST",
                url: "<%=basePath%>order/updateOrder",
                data: data.field,
                success: function (data) {
                    layer.msg(data.msg);
                }
            });

            form.render();


        });
        /**
         * 投诉工单
         * */
        form.on('submit(userComplain)', function (data) {
            /*layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            });*/

            $.ajax({
                type: "get",
                url: "<%=basePath%>order/complainOrder",
                data: data.field,
                success: function (data) {
                    layer.msg(data.msg);
                }
            });
            form.render();

        });

        /**
         * 取消工单
         * */
        form.on('submit(cancelOrder)', function (data) {
            /*layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            });*/

            $.ajax({
                type: "POST",
                url: "<%=basePath%>order/cancelOrder",
                data: data.field,
                success: function (data) {
                    layer.msg(data.msg);
                }
            });

            form.render();
        });
    });
    writeDateInfo();
</script>

</body>
</html>
